package com.es.template;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.es.util.mail.MailInfo;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.webwork.interceptor.ServletResponseAware;
import com.opensymphony.xwork.ActionSupport;

public class DownLoadExcelTemplateAction extends ActionSupport implements ServletRequestAware,ServletResponseAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	HttpServletRequest request;
	HttpServletResponse response;
	 
	   public String execute()throws Exception
	   {
		   response.setContentType("APPLICATION/OCTET-STREAM");   
	        response.setHeader("Content-Disposition","attachment;filename=\"excel.rar\"");
	        int BUFSIZE = 1024 * 8;        
	        int rtnPos = 0;
	        byte[] buffs = new byte[ BUFSIZE ];
	        FileInputStream inStream = null;
	        InputStream is = null;
	        try{
	        	 is = MailInfo.class.getClassLoader().getResourceAsStream(
	    	    "excel.rar");
	        	//inStream =new FileInputStream("D:\\csq\\workplace\\hrm2\\WebContent\\jsp\\template\\excel.rar");  
                while((rtnPos=is.read(buffs)) >0)   
                    response.getOutputStream().write(buffs,0,rtnPos);   
                response.getOutputStream().close();   
                is.close();	          
	            
	        }catch(IOException e){
	        }finally{
	            try{
	                if ( inStream != null ){
	                    inStream.close();
	                    inStream = null;
	                }
	                if ( is != null ){
	                    is.close();
	                    is = null;
	                }
	            }catch (IOException e){
	            }
	        }

		   return "";
	   }
	
	   public void setServletRequest(HttpServletRequest request) {
		     this.request = request;
		   }
	   public void setServletResponse(HttpServletResponse response) {
		    this.response = response;
		  }
}
